<template>
  <div class="chart-statistics">
    <div class="stat-card theme-blue">
      <div class="column-caption">
        <span class="caption-text">{{ columnChartTitle }}</span>
      </div>
      <div class="chart-container chart-component">
        <WordDataColumn :data="columnChartData" />
      </div>
    </div>
    <div class="stat-card theme-cyan">
      <div class="circle-caption">
        <span class="caption-text">{{ circleChartTitle }}</span>
      </div>
      <div class="chart-container chart-component">
        <WordDataCircle :data="circleChartData" />
      </div>
    </div>
  </div>
</template>

<script>
import WordDataColumn from "../WordDataColumn.vue";
import WordDataCircle from "../WordDataCircle.vue";
import "../../styles/statistics-common.css";

export default {
  name: "ChartStatistics",
  components: {
    WordDataColumn,
    WordDataCircle,
  },
  props: {
    columnChartTitle: {
      type: String,
      default: "近七天学习统计"
    },
    circleChartTitle: {
      type: String,
      default: "单词统计"
    },
    columnChartData: {
      type: Array,
      default: () => []
    },
    circleChartData: {
      type: Array,
      default: () => []
    }
  }
};
</script>

<style scoped>
.chart-statistics {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  min-height: 380px;
  align-items: stretch;
  padding: 25px;
  margin-bottom: 40px;
}

.stat-card {
  width: 100%;
  flex: 1.2;
}

.stat-card:last-child {
  min-width: 320px;
  flex: 1.8;
  max-width: 500px;
}

/* 放大图表容器 */
.chart-container {
  margin-top: 20px;
  border-radius: 10px;
  overflow: hidden;
  transition: all 0.3s ease;
  min-height: 320px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.chart-container:hover {
  transform: translateY(-2px);
  background: rgba(255, 255, 255, 0.12);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

/* 确保图表组件正确显示 */
.chart-container :deep(.chart-component),
.chart-container :deep(#container-column),
.chart-container :deep(#container-circle) {
  position: relative !important;
  z-index: 2 !important;
  background: transparent !important;
  border: none !important;
  min-height: 300px !important;
}

.column-caption,
.circle-caption {
  display: flex;
  align-items: center;
  margin-bottom: 15px;
  position: relative;
  z-index: 3;
}

/* 覆盖统一样式中可能冲突的部分 */
.caption-text {
  font-size: 17px !important;
  color: rgba(255, 255, 255, 0.95) !important;
  font-weight: 700 !important;
  letter-spacing: 0.5px !important;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3) !important;
  position: relative;
}

.caption-text::before {
  content: '';
  position: absolute;
  left: -18px;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 18px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 2px;
}

/* 为图表添加加载动画 */
@keyframes chartFadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chart-container > * {
  animation: chartFadeIn 0.8s ease-out;
}

/* 饼图容器放大 */
.stat-card:last-child .chart-container {
  max-width: 380px;
  margin: 20px auto 0 auto;
}

/* 确保图表内容可见 */
.chart-container :deep(.g2-tooltip),
.chart-container :deep(.g2-legend),
.chart-container :deep(.g2-axis) {
  z-index: 10 !important;
}

@media (max-width: 707px) {
  .chart-statistics {
    display: flex;
    flex-direction: column;
    width: 100%;
    padding: 0 15px;
    gap: 20px;
  }
  
  .stat-card:last-child {
    width: 100%;
    margin: 0;
    min-width: unset;
    max-width: unset;
  }
  
  .chart-container {
    min-height: 280px;
  }
  
  .stat-card:last-child .chart-container {
    max-width: 100%;
    margin: 20px 0 0 0;
  }
}
</style>
